package cn.javacc.core.vo;

import java.util.List;

public class PageData<T> {
	private List<T> data;
	private Integer pageSize;
	private Integer totalRows;
	private Integer currentPage;

	public Integer getPrePage() {
		if (currentPage > 1) {
			return currentPage - 1;
		}
		return 1;
	}

	public Integer getNextPage() {
		if (currentPage == getTotalPage()) {
			return currentPage;
		}
		return currentPage + 1;
	}

	public Integer getTotalPage() {
		return (int) Math.ceil((float) totalRows / pageSize);
	}

	public Integer getStartRow() {
		if (currentPage == 0) {
			return 0;
		}
		return (currentPage - 1) * pageSize;
	}

	public Integer getEndRow() {
		if (getStartRow() + pageSize < totalRows) {
			return getStartRow() + pageSize;
		} else {
			return totalRows;
		}
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(Integer totalRows) {
		this.totalRows = totalRows;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		if (currentPage > this.getTotalPage()) {
			this.currentPage = getTotalPage();
		} else if (currentPage < 1) {
			this.currentPage = 1;
		} else {
			this.currentPage = currentPage;
		}
	}

}
